﻿using System;
using System.IO;
using Microsoft.Office.PowerPoint.STAMP.Core;
using Microsoft.Office.PowerPoint.STAMP.View;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace Microsoft.Office.PowerPoint.STAMP.Presenter
{
    /// <summary>
    /// Import Presenter class.
    /// </summary>
    /// <remarks>
    /// MV Patterns: MVP design pattern.
    /// </remarks>
    public class ImportPresenter : Presenter<IImportView>
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="view">The view.</param>
        public ImportPresenter(IImportView view)
            : base(view)
        {
            Initialize();
        }

        private void Initialize()
        {
           
        }

        private void GetExtention(string filePath)
        {
            View.Extention = Path.GetExtension(filePath);
        }

        public void LoadCaptionsListFromFile()
        {
            try
            {
                GetExtention(View.FilePath);
                switch (View.Extention.ToLower())
                {
                    case ".xml":
                        View.CaptionsList = Mapper.ToClosedCaptionsList(TTMLReader.ParseTTML(View.FilePath));
                        break;
                }
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "Global Policy");
                if (rethrow)
                    throw;
            }
        }
    }
}